#include "win32dialogs.h"

#ifdef __WIN32__

#include <windows.h>
int show_open_box(char* file_name, const char* _title, const char* _filter, bool save_box)
{
    char filename[1024] = "";
    char filetitle[1024] = "";
    char filter[256] = "";
    char initdir[256] = ".\\";
    char title[256] = "";
    strcpy(title, _title);
    int n = strlen(_filter);
    int i;
    for (i = 0; i < n; i++)
    {
        if (_filter[i] == '|')
            filter[i] = 0;
        else
            filter[i] = _filter[i];
    }
    filter[i] = 0;
    OPENFILENAME ofn;
    memset(&ofn, 0, sizeof(ofn));
    ofn.lStructSize = sizeof(ofn);
    ofn.hwndOwner = NULL;
    ofn.hInstance = GetModuleHandle(NULL);
    ofn.lpstrFilter = filter;
    ofn.nFilterIndex = 1;
    ofn.lpstrFile = filename;
    ofn.nMaxFile = 1024;
    ofn.lpstrFileTitle = filetitle;
    ofn.nMaxFileTitle = 1024;
    ofn.lpstrInitialDir = initdir;
    ofn.lpstrTitle = title;
    ofn.Flags = OFN_EXPLORER;
    if (save_box)
    {
        ofn.Flags |= OFN_OVERWRITEPROMPT;
        if (GetSaveFileName(&ofn) == 0 || filename == NULL)
            return 0;
    }
    else
    {
        if (GetOpenFileName(&ofn) == 0 || filename == NULL)
            return 0;
    }
    strcpy(file_name, filename);
    return 1;
}

#else

#include <Xm/Xm.h>
#include <Xm/PushB.h>

void pushed_fn(Widget, /*XtPointer*/void*, /*XmPushButtonCallbackStruct **/void*);

int show_open_box(char* file_name, const char* _title, const char* _filter, bool save_box)
{
    int argc = 0;
    char *argv[] = { "DollAnim", NULL };

    Widget        toplevel, button;
    XtAppContext  app;
    void          button_pushed();
    XmString 	  label;

    XtSetLanguageProc (NULL, NULL, NULL);

    toplevel = XtVaAppInitialize (&app, "Hello", NULL, 0,
        &argc, argv, NULL, NULL);

    label = XmStringCreateLocalized ("Push here to say hello");
    button = XtVaCreateManagedWidget ("pushme",
        xmPushButtonWidgetClass, toplevel,
        XmNlabelString, label,
        NULL);
    XmStringFree (label);
   // XtAddCallback (button, XmNactivateCallback, button_pushed, NULL);

    XtRealizeWidget (toplevel);
    XtAppMainLoop (app);

    return 0;
}

void pushed_fn(Widget w, void* client_data, void* cbs)
{
    printf("Don't Push Me!!\n");
}


int main(int argc, char* argv[])
{
    Widget        toplevel, button;
    XtAppContext  app;
    void          button_pushed();
    XmString 	  label;

    XtSetLanguageProc (NULL, NULL, NULL);

    toplevel = XtVaAppInitialize (&app, "Hello", NULL, 0,
        &argc, argv, NULL, NULL);

    label = XmStringCreateLocalized ("Push here to say hello");
    /*button = XtVaCreateManagedWidget ("pushme",
        xmPushButtonWidgetClass, toplevel,
        XmNlabelString, label,
        NULL);*/
    //XmStringFree (label);
    //XtAddCallback (button, XmNactivateCallback, button_pushed, NULL);

    XtRealizeWidget (toplevel);
    XtAppMainLoop (app);
    return 0;
}

#endif

